{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "adef6fe2",
   "metadata": {},
   "source": [
    "## 3. 作业\n",
    "\n",
    "* 1. 尝试创建detect.py 并实现功能调用\n",
    "* 2. 尝试创建analyze.py\\campare.py\\search.py 并实现功能调用\n",
    "* 3. 尝试存放宿舍4位同学的人脸信息到 人脸数据集（XXX栋XXX宿舍）：\n",
    "\n",
    "> A. 完善faceset信息\n",
    "\n",
    "> B. 实现人脸搜索和人脸对比，打印结果：是本人OR 不是本人"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ebcb293e",
   "metadata": {},
   "source": [
    "# 尝试创建detect.py 并实现功能调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "17874369",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 封装函数 \n",
    "# import requests\n",
    "# def face_detect(API_key,API_sercret,image_path):\n",
    "#     \"\"\"该函数为调用face++ face_detect接口\"\"\"\n",
    "#     base_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'\n",
    "#     files = {'image_file':(image_path, open(image_path, 'rb'), 'multipart/form-date')}\n",
    "#     payload = {\n",
    "#         'api_key':API_key,\n",
    "#         'api_secret':API_sercret,\n",
    "#     }\n",
    "\n",
    "#     r = requests.post(base_url, params = payload,files = files )\n",
    "#     return r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5bd744f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "API_key = '-sktIe7XLrdVWO6YPccL5lz1RUb5-gQQ'\n",
    "API_sercret = 'InL8GaEbniNEzTHg3GqUrj329rqRAU81'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f673df11",
   "metadata": {},
   "outputs": [],
   "source": [
    "import detect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ba664c93",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module detect:\n",
      "\n",
      "NAME\n",
      "    detect\n",
      "\n",
      "FUNCTIONS\n",
      "    face_detect(API_key, API_sercret, image_path)\n",
      "        该函数为调用face++ face_detect接口\n",
      "\n",
      "FILE\n",
      "    d:\\大学\\api\\week02\\detect.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(detect)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8e44e60b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648371827,8e0e5f49-aaa6-477f-be8f-cff9599444c6',\n",
       " 'time_used': 196,\n",
       " 'faces': [{'face_token': 'd449a42b9b1e0c11d229a1b991c87e4c',\n",
       "   'face_rectangle': {'top': 377, 'left': 454, 'width': 167, 'height': 167}}],\n",
       " 'image_id': 'xOZeHxrHb9ui+ItzT6atDg==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "detect.face_detect(API_key,API_sercret,'kyrie.jpg')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "38689265",
   "metadata": {},
   "source": [
    "# 尝试创建analyze.py 并实现功能调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ea7cffb4",
   "metadata": {},
   "outputs": [],
   "source": [
    "face1 = detect.face_detect(API_key,API_sercret,'kyrie.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "27907038",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'7ee693bcdde39f1ed22ce798e585a7f7'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_tokens = face1['faces'][0]['face_token']\n",
    "face_tokens"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "6f33f8f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import analyze"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "5d3fce57",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module analyze:\n",
      "\n",
      "NAME\n",
      "    analyze\n",
      "\n",
      "FUNCTIONS\n",
      "    face_analyze(API_key, API_sercret, face_tokens, landmark=1, attributes=None, face_rectangle=None, beauty_score_min=0, beauty_score_max=100)\n",
      "        该函数为调用face++ face_analyze接口\n",
      "\n",
      "FILE\n",
      "    d:\\大学\\api\\week02\\analyze.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(analyze)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e1d11bc2",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 66,\n",
       " 'request_id': '1648371993,54f75dec-e340-4b16-aaa9-ce83c562db9b',\n",
       " 'faces': [{'landmark': {'mouth_upper_lip_left_contour2': {'y': 479, 'x': 517},\n",
       "    'mouth_upper_lip_top': {'y': 478, 'x': 540},\n",
       "    'mouth_upper_lip_left_contour1': {'y': 477, 'x': 532},\n",
       "    'left_eye_upper_left_quarter': {'y': 401, 'x': 491},\n",
       "    'left_eyebrow_lower_middle': {'y': 387, 'x': 496},\n",
       "    'mouth_upper_lip_left_contour3': {'y': 484, 'x': 521},\n",
       "    'right_eye_top': {'y': 399, 'x': 579},\n",
       "    'left_eye_bottom': {'y': 410, 'x': 500},\n",
       "    'right_eyebrow_lower_left_quarter': {'y': 390, 'x': 568},\n",
       "    'right_eye_pupil': {'y': 404, 'x': 581},\n",
       "    'mouth_lower_lip_right_contour1': {'y': 483, 'x': 558},\n",
       "    'mouth_lower_lip_right_contour3': {'y': 492, 'x': 554},\n",
       "    'mouth_lower_lip_right_contour2': {'y': 488, 'x': 566},\n",
       "    'contour_chin': {'y': 544, 'x': 541},\n",
       "    'contour_left9': {'y': 541, 'x': 519},\n",
       "    'left_eye_lower_right_quarter': {'y': 408, 'x': 509},\n",
       "    'mouth_lower_lip_top': {'y': 484, 'x': 540},\n",
       "    'right_eyebrow_upper_middle': {'y': 379, 'x': 582},\n",
       "    'left_eyebrow_left_corner': {'y': 394, 'x': 470},\n",
       "    'right_eye_bottom': {'y': 409, 'x': 579},\n",
       "    'contour_left7': {'y': 519, 'x': 485},\n",
       "    'contour_left6': {'y': 504, 'x': 473},\n",
       "    'contour_left5': {'y': 487, 'x': 464},\n",
       "    'contour_left4': {'y': 468, 'x': 459},\n",
       "    'contour_left3': {'y': 448, 'x': 457},\n",
       "    'contour_left2': {'y': 429, 'x': 456},\n",
       "    'contour_left1': {'y': 409, 'x': 457},\n",
       "    'left_eye_lower_left_quarter': {'y': 409, 'x': 491},\n",
       "    'contour_right1': {'y': 405, 'x': 616},\n",
       "    'contour_right3': {'y': 443, 'x': 619},\n",
       "    'contour_right2': {'y': 424, 'x': 618},\n",
       "    'mouth_left_corner': {'y': 484, 'x': 502},\n",
       "    'contour_right4': {'y': 463, 'x': 619},\n",
       "    'contour_right7': {'y': 516, 'x': 597},\n",
       "    'right_eyebrow_left_corner': {'y': 389, 'x': 554},\n",
       "    'nose_right': {'y': 443, 'x': 567},\n",
       "    'nose_tip': {'y': 437, 'x': 533},\n",
       "    'contour_right5': {'y': 482, 'x': 615},\n",
       "    'nose_contour_lower_middle': {'y': 455, 'x': 536},\n",
       "    'left_eyebrow_lower_left_quarter': {'y': 389, 'x': 483},\n",
       "    'mouth_lower_lip_left_contour3': {'y': 493, 'x': 525},\n",
       "    'right_eye_right_corner': {'y': 407, 'x': 595},\n",
       "    'right_eye_lower_right_quarter': {'y': 409, 'x': 588},\n",
       "    'mouth_upper_lip_right_contour2': {'y': 479, 'x': 562},\n",
       "    'right_eyebrow_lower_right_quarter': {'y': 391, 'x': 595},\n",
       "    'left_eye_left_corner': {'y': 406, 'x': 484},\n",
       "    'mouth_right_corner': {'y': 483, 'x': 576},\n",
       "    'mouth_upper_lip_right_contour3': {'y': 484, 'x': 558},\n",
       "    'right_eye_lower_left_quarter': {'y': 408, 'x': 571},\n",
       "    'left_eyebrow_right_corner': {'y': 388, 'x': 523},\n",
       "    'left_eyebrow_lower_right_quarter': {'y': 388, 'x': 510},\n",
       "    'right_eye_center': {'y': 405, 'x': 579},\n",
       "    'nose_left': {'y': 445, 'x': 512},\n",
       "    'mouth_lower_lip_left_contour1': {'y': 483, 'x': 521},\n",
       "    'left_eye_upper_right_quarter': {'y': 401, 'x': 509},\n",
       "    'right_eyebrow_lower_middle': {'y': 389, 'x': 582},\n",
       "    'left_eye_top': {'y': 399, 'x': 500},\n",
       "    'left_eye_center': {'y': 405, 'x': 500},\n",
       "    'contour_left8': {'y': 531, 'x': 501},\n",
       "    'contour_right9': {'y': 540, 'x': 563},\n",
       "    'right_eye_left_corner': {'y': 406, 'x': 563},\n",
       "    'mouth_lower_lip_bottom': {'y': 494, 'x': 540},\n",
       "    'left_eyebrow_upper_left_quarter': {'y': 382, 'x': 481},\n",
       "    'left_eye_pupil': {'y': 404, 'x': 500},\n",
       "    'right_eyebrow_upper_left_quarter': {'y': 380, 'x': 566},\n",
       "    'contour_right8': {'y': 530, 'x': 581},\n",
       "    'right_eyebrow_right_corner': {'y': 394, 'x': 609},\n",
       "    'right_eye_upper_left_quarter': {'y': 401, 'x': 570},\n",
       "    'left_eyebrow_upper_middle': {'y': 377, 'x': 496},\n",
       "    'right_eyebrow_upper_right_quarter': {'y': 383, 'x': 598},\n",
       "    'nose_contour_left1': {'y': 407, 'x': 527},\n",
       "    'nose_contour_left2': {'y': 431, 'x': 520},\n",
       "    'mouth_upper_lip_right_contour1': {'y': 477, 'x': 547},\n",
       "    'nose_contour_right1': {'y': 406, 'x': 550},\n",
       "    'nose_contour_right2': {'y': 429, 'x': 557},\n",
       "    'mouth_lower_lip_left_contour2': {'y': 489, 'x': 513},\n",
       "    'contour_right6': {'y': 501, 'x': 608},\n",
       "    'nose_contour_right3': {'y': 451, 'x': 552},\n",
       "    'nose_contour_left3': {'y': 452, 'x': 523},\n",
       "    'left_eye_right_corner': {'y': 406, 'x': 517},\n",
       "    'left_eyebrow_upper_right_quarter': {'y': 379, 'x': 512},\n",
       "    'right_eye_upper_right_quarter': {'y': 401, 'x': 588},\n",
       "    'mouth_upper_lip_bottom': {'y': 485, 'x': 540}},\n",
       "   'face_rectangle': {'width': 167, 'top': 377, 'left': 454, 'height': 167},\n",
       "   'face_token': '7ee693bcdde39f1ed22ce798e585a7f7'}]}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "analyze.face_analyze(API_key,API_sercret,face_tokens)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "84f8d88a",
   "metadata": {},
   "source": [
    "# 尝试创建compare.py 并实现功能调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "9203baae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648375078,3594ebb4-f259-4381-9315-71f21f7e8161',\n",
       " 'time_used': 212,\n",
       " 'faces': [{'face_token': '788b937a744e743f2be0139b1445d88a',\n",
       "   'face_rectangle': {'top': 377, 'left': 454, 'width': 167, 'height': 167}}],\n",
       " 'image_id': 'xOZeHxrHb9ui+ItzT6atDg==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "detect.face_detect(API_key,API_sercret,'kyrie.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "0dee80aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'9221be383e6bd42f3c130d6ad79c823e'"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_token1 = face1['faces'][0]['face_token']\n",
    "face_token1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "081bcc6b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648375098,b95582a6-b07c-42c7-a2f7-2c45f8943d49',\n",
       " 'time_used': 78,\n",
       " 'faces': [{'face_token': '3e84b65b1e81a5236671ea33e2bcf1c9',\n",
       "   'face_rectangle': {'top': 182, 'left': 388, 'width': 209, 'height': 209}}],\n",
       " 'image_id': '5qMAVP5Hs+BBSOX2jCWyCw==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "detect.face_detect(API_key,API_sercret,'kyrie2.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "87bfe84c",
   "metadata": {},
   "outputs": [],
   "source": [
    "face2 = detect.face_detect(API_key,API_sercret,'kyrie2.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "be1bf538",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'a1be22c8e4c9fc76e2d54b7f1b567a39'"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_token2 = face2['faces'][0]['face_token']\n",
    "face_token2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "c7a885aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "import compare"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "f8d0dd7b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module compare:\n",
      "\n",
      "NAME\n",
      "    compare\n",
      "\n",
      "FUNCTIONS\n",
      "    face_compare(API_key, API_sercret, face_token1, face_token2)\n",
      "        该函数为调用face++ face_compare接口\n",
      "\n",
      "FILE\n",
      "    d:\\大学\\api\\week02\\compare.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(compare)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "8c2297d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648375141,61da1d4a-2c9e-47b7-a204-76cf92b4c3af',\n",
       " 'time_used': 434,\n",
       " 'confidence': 60.757,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-4': 69.101, '1e-5': 73.975}}"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "compare.face_compare(API_key,API_sercret,face_token1,face_token2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e922079",
   "metadata": {},
   "source": [
    "### 手动添加人脸信息 如何自动？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "id": "9d529955",
   "metadata": {},
   "outputs": [],
   "source": [
    "update_FaceSet_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/update'\n",
    "\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_secret,\n",
    "    'faceset_token':faceset_token,\n",
    "    'new_outer_id':'布鲁克林',\n",
    "    'display_name':'kyrie3',\n",
    "    'user_data':'3'\n",
    "}\n",
    "r = requests.post(url=update_FaceSet_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "id": "f5054c10",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 172,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "id": "1504f617",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '62c4653d392a3041ebb082687ffc52d6',\n",
       " 'request_id': '1648375784,9f96a726-61ff-44fc-ab04-751a70588e7c',\n",
       " 'time_used': 66,\n",
       " 'outer_id': '布鲁克林'}"
      ]
     },
     "execution_count": 173,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7cc969d",
   "metadata": {},
   "source": [
    "# 尝试创建search.py，并实现功能调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "id": "63b936d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "getfacesets_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/getfacesets\"\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_sercret,\n",
    "}\n",
    "r = requests.post(url = getfacesets_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "id": "37eaf201",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 118,\n",
       " 'facesets': [{'faceset_token': '62c4653d392a3041ebb082687ffc52d6',\n",
       "   'outer_id': '布鲁克林',\n",
       "   'display_name': 'kyrie3',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '2ba4f11f87bebbacd8b3d6804e9f4593',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '4370b7427473560f6dd208a174982c12',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '51c6b21adf0b441243dc6d258c0153c3',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '0c586a5911978433c120092dc2d32eab',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '660fe587f551457dd15f507ed217fc0c',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '176e96ef3a297a168ffb7563fe2b4eda',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '6c3483005e4b82f32f734f90787a8efe',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '3d97d71a3bb2855c406f3e4109a1ed12',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '0beec3af6b7619f3238d1b5ac7c52989',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': 'da39360765aadd58e782b690aae9d747',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': 'a4693d07dafab7de16bc06de3c37c3dd',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '3ab2baa5159adf9fe9297e818e8e6385',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '06116bca7ab8661a7cfc2e813cc68c25',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '300767fac13e69a654f5fab030a711da',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': 'f8285c50862f957e0a5f6533afe930cb',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': '3520e6a166c0a6441a81bdde4610ba0d',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': 'b56694b6ce505faeefeaf38306f70702',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': 'f7388eddafeea8905e61d069cdafe32f',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''},\n",
       "  {'faceset_token': 'c56bc3d99d9f0af99dca9f0d6ef1a5a7',\n",
       "   'outer_id': 'API020305',\n",
       "   'display_name': '2020级网新API周二上午班',\n",
       "   'tags': ''}],\n",
       " 'request_id': '1648375786,4e2d6de6-661b-4c7c-8d74-c61042273893'}"
      ]
     },
     "execution_count": 175,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "id": "c2b5b948",
   "metadata": {},
   "outputs": [],
   "source": [
    "faceset_tokens = r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "id": "b28fe7eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'62c4653d392a3041ebb082687ffc52d6'"
      ]
     },
     "execution_count": 159,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "faceset_token = faceset_tokens['facesets'][0]['faceset_token']\n",
    "faceset_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "id": "5b554cad",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648375634,8f40efa6-ae54-4624-9721-e7386db3d68f',\n",
       " 'time_used': 176,\n",
       " 'faces': [{'face_token': 'a7b48fbf0cfb43194ebd005bd127a509',\n",
       "   'face_rectangle': {'top': 155, 'left': 599, 'width': 116, 'height': 116}}],\n",
       " 'image_id': 'MI8UsZfbWNmSLFVhd0WBkA==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 160,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "detect.face_detect(API_key,API_sercret,'kyrie3.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "id": "9b0af612",
   "metadata": {},
   "outputs": [],
   "source": [
    "face3 = detect.face_detect(API_key,API_sercret,'kyrie3.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "id": "f52ae2dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'3f5a483a4b93999eb2bf56725f45876f'"
      ]
     },
     "execution_count": 177,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_token = face3['faces'][0]['face_token']\n",
    "face_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "id": "b468372e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import search"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "id": "1fd490ca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module search:\n",
      "\n",
      "NAME\n",
      "    search\n",
      "\n",
      "FUNCTIONS\n",
      "    face_search(API_key, API_sercret, faceset_token, face_token)\n",
      "        该函数为调用face++ face_search接口\n",
      "\n",
      "FILE\n",
      "    d:\\大学\\api\\week02\\search.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(search)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "id": "f45dc0f4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 79,\n",
       " 'error_message': 'EMPTY_FACESET',\n",
       " 'request_id': '1648375848,dd97a437-0ba1-4317-a549-89cc3951d5af'}"
      ]
     },
     "execution_count": 180,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "search.face_search(API_key,API_sercret,faceset_token,face_token)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "208b5aac",
   "metadata": {},
   "source": [
    "### 为什么是空人脸 人脸库没有录入。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1ff94f9d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
